﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKRGeometry;

namespace HYPretreatmentModeling
{
	internal class LoopInfo
	{
		public List<Curve> Curves
		{
			get
			{
				return this.m_lstCurves;
			}
		}

		public XYZ RectMin
		{
			get
			{
				return this.m_ptRectMin;
			}
		}

		public XYZ RectMax
		{
			get
			{
				return this.m_ptRectMax;
			}
		}

		public LoopInfo(List<Curve> lstCurves, double dEps = 0.0001)
		{
			this.m_dEps = dEps;
			this.m_lstCurves = lstCurves;
			this.GetRect();
		}

		private void GetRect()
		{
			if (this.m_lstCurves.Count != 4)
			{
				return;
			}
			this.m_ptRectMin = new XYZ(double.MaxValue, double.MaxValue, 0.0);
			this.m_ptRectMax = new XYZ(double.MinValue, double.MinValue, 0.0);
			for (int i = 0; i < 4; i++)
			{
				XYZ endPoint = this.m_lstCurves[i].GetEndPoint(0);
				if (Geometry.Lessthan_Or_Equal(endPoint.X, this.m_ptRectMin.X, this.m_dEps) && Geometry.Lessthan_Or_Equal(endPoint.Y, this.m_ptRectMin.Y, this.m_dEps))
				{
					this.m_ptRectMin = new XYZ(endPoint.X, endPoint.Y, 0.0);
				}
				if (Geometry.Greaterthan_Or_Equal(endPoint.X, this.m_ptRectMax.X, this.m_dEps) && Geometry.Greaterthan_Or_Equal(endPoint.Y, this.m_ptRectMax.Y, this.m_dEps))
				{
					this.m_ptRectMax = new XYZ(endPoint.X, endPoint.Y, 0.0);
				}
			}
		}

		private double m_dEps = 0.0001;

		private List<Curve> m_lstCurves = new List<Curve>();

		private XYZ m_ptRectMin = new XYZ();

		private XYZ m_ptRectMax = new XYZ();
	}
}
